package com.bsj.power.pls.queue.service.impl.handle;

import cn.hutool.core.util.HexUtil;
import com.bsj.consumerQ.function.HandleRun;
import com.bsj.power.common.util.DataUtil;
import com.bsj.power.common.util.DateUtils;
import com.bsj.power.common.util.ExceptionUtil;
import com.bsj.power.pls.config.net.netty.protocol.UWBAck;
import com.bsj.power.pls.queue.service.impl.tactic.FusionDataConsume;
import com.bsj.power.pls.queue.service.impl.tactic.SequentialConsumeQueue;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description RTK数据广播
 * @date 2024/10/12
 */
@Slf4j
@Service
public class QueueRTKBroadcastHandle implements HandleRun {

    @Override
    public void doRun(List<byte[]> list) {
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        try {
            LocalDateTime now = LocalDateTime.now();
            for (byte[] bytes : list) {
                if (SequentialConsumeQueue.checkSize()) {
                    SequentialConsumeQueue.putData(bytes);
                } else {
                    log.info("RTK广播顺序队列已满,超出数据丢弃：{}", HexUtil.encodeHexStr(bytes, false));
                }
//                if (DateUtils.checkTimeByMinute(now)) {
//                    FusionDataConsume.putData(bytes);
//                } else {
//                    log.info("RTK广播数据接收不在指定时间内,数据丢弃：{}", HexUtil.encodeHexStr(bytes, false));
//                }
            }
        } catch (Exception e) {
            log.error("RTK数据广播处理失败： {}", ExceptionUtil.getStackStr(e));
            return;
        }
    }

    public static void main(String[] args) {
//        String s = "D300133ED004033A6AEC369B8C852EB4AB45B12D313E6A20D1D30040412F87A61F8F05FDC4000000B400000D0833E6A5662AB28BAC0CF58024C60AF219B95D6091CFEE2004326D45165400C404268D501932740468377FEE8B02E0BAF54F68D3003E4153947C6C6BAF421FC0000F68012E3C300E70F7D462EED750118149F88BB818EE952AE6FA1FC039AC8CC912A03902339DA7D1CBE6F512319FFB035FB5002F2A66D3003F4165547C4A6BF42E0A803FFECDFD73E6140EDC99D6F5AB0D380C6800296F943402A81392D60A8002D9ECA8BB6FFDA2752F8F319F8DD973E3CFFC12AFF3FA00D777C4D300864320047D320C8200200405298400000000202041007474447C2626A2A2A8A62226A5450DFD83FAF7640BA81BAD3A867600F89915524544788E0C74DA2FDBDA23CA9F882F07DBB284697C073A782F62D0F1A2437104095AEB5C0D20E2E2BE17800C9D340276BEC636FFAB16FF90F7CE334FFFDCBFF8FBAFFF00014B93D15312CB1454B144CF00E1E3A5D3004A43C004C42B8142002000B00200000000002040000077A5262526A458F60F8BEE45DB9FEFDC0CB029B02881B87D85A5010097FC265FFCCA3F8520F76683D83B7BDFECFF0103B0D8F3EF00410EEED300654460047D320C8200200A7800004000000020810100444447A27A7A9A727282E92B42F9E37B7F3D1B6616C69F005FEF1864C111A985A35F470BB16505A4C40DCBD80642FF5A49869F96218FC0630C418D5D065B3FEFF1A77FFF77FFF8013CB1CB1CD1CF1BC0A3C1D7D300EC4640047D3131C2002058849A041800000020820101721C6421BDC7719BE3C403DBE3D272BA72925A7C1E6B17FFB3E6EFA495C8905A20BCAE0A8C3E18548BA2167131345D97D6B7AB3DAF2443FB23F673EF53FAE829D077E100A04903D104AC092A1C584668FD6E8C1C64084C15762063E0A5FF7C529E6924057E801BDAA0676FA5A0DBFEEEE5FAC087AD544100FE80201FF6E98FEAD51FD9EA0095CFFB755802D5803A880221C868FD17F9169FEA22F2F858106FD7CEA7FF102104C8401B7E9846177FFFDFFFBFB7DFFFBDFFDF7FFDDFFFE00000005765B0C9446FC10472CD2D10C4F471CCFC2FC30CD54B48031A52D3004E4640047D3131C000200000000003000010208201016E387A797B3259F2B32FF667DCEA98F437A46CD11A082DFFD9324F2B9D3CE1CCFF8B4FC537805A4541A73905CEDBFFFFFBFC02DAEAB209AAC05BB86BD3000C4CE0040FF1F3F1F3F1F3F1F3E2D529D300153EE004033A6AEC369B8C852EB4AB45B12D313EEA6094CCBFD3003D3FB3D1F040124F80520000271C23F44FF48C36EE0373CF1BF6110846016A0DDDA10DB28A8052FF4F403BE9F900312626C2041E5F37AB8563FFA253EA009ED433D3002D3FC381B100C5112DD3DC4D36E184B0C314252380B549DD9F7F18A1C00D038BF181223AC8E40000000A00000500E7141E";
//        byte[][] bytes = DataUtil.divideData(HexUtil.decodeHex(s), 57);
//        for (int i = 0; i < bytes.length; i++) {
//            //当前包内容
//            byte[] nowData = bytes[i];
//            byte[] rtkSend = UWBAck.rtkSend(nowData, i + 1, bytes.length, 1);
//            String rtkSendStr = HexUtil.encodeHexStr(rtkSend, false);
//            System.out.println(rtkSendStr);
//        }
        LocalDateTime now = LocalDateTime.now();
        System.out.println(DateUtils.checkTimeByMinute(now));
        System.out.println(DateUtils.checkTimeByMinuteInt(now));
    }
}
